<?php

class Euso_Object
{
	public static function getInstance($objClassIdName, $objId = NULL, $objIdName = NULL)
	{
		$instance = NULL;
		if (empty($objClassIdName) === FALSE) {
			$objClass = Euso_ObjectClass::getInstanceByIdName($objClassIdName);
			if (($objClass instanceof Euso_ObjectClass) === FALSE) {
				return NULL;
			}
			$objReg = $objClass->getRegistry();
			if ($objReg) {
				if (intval($objId) > 0) {
					$instance = $objReg->getById($objId);
				} else {
					$instance = $objReg->getByIdName($objIdName);
				}
			} else {
				$objClassName = $objClass->getClassName();
				if (empty($objClassName)) {
					return NULL;
				}
				$tmpObjInst = new $objClassName;
				if (intval($objId) > 0) {
					$instance = $tmpObjInst->getInstanceById($objId);
				} else {
					$instance = $tmpObjInst->getInstanceByIdName($objIdName);
				}
			}
		}
		return $instance;
	}
}
